package com.simple.simple_view.handler;

import com.simple.simple_view.domain.ResponseResult;
import com.simple.simple_view.domain.enums.AppHttpCodeEnum;
import com.simple.simple_view.exception.SystemException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/*
 *@description: 全局异常处理
 *@author: hisen
 *@Time: 2023/10/28  19:26
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(SystemException.class)
    public ResponseResult systemExceptionHandler(SystemException e){
        log.error(e.getMessage(),e);
        return ResponseResult.errorResult(e.getCode(),e.getMsg());
    }
    @ExceptionHandler(RuntimeException.class)
    public ResponseResult runtimeExceptionHandler(RuntimeException e){
        log.error(e.getMessage(),e);
        return ResponseResult.errorResult(AppHttpCodeEnum.SYSTEM_ERROR);
    }
}
